import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-05-22
 * Time: 19:27
 */
public class Test {
    public static void mySort(Comparable[] comparables) {
        for (int i = 0; i < comparables.length - 1; i++) {
            boolean flg = true;
            for (int j = 0; j < comparables.length - 1 - i; j++) {
                if (comparables[j].compareTo(comparables[j + 1]) > 0) {
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j + 1];
                    comparables[j + 1] = tmp;
                    flg = false;
                }
            }
            if (flg == true) {
                break;
            }
        }
    }

    public static void main2(String[] args) {
        Studnet[] studnets = new Studnet[]{
                new Studnet("dings",18),
                new Studnet("perper",3),
                new Studnet("huahua",10),
                new Studnet("abc",30)
        };
        System.out.println("排序前："+Arrays.toString(studnets));
        mySort(studnets);
        System.out.println("排序后："+Arrays.toString(studnets));
    }



    public static void main(String[] args) {

        Studnet[] studnets = new Studnet[3];
        studnets[0] = new Studnet("dings",18);
        studnets[1] = new Studnet("huahua",10);
        studnets[2] = new Studnet("abc",4);

        AgeComparator ageComparator = new AgeComparator();
        NameComparator nameComparator = new NameComparator();

        if(ageComparator.compare(studnets[0],studnets[1]) > 0) {
            System.out.println(studnets[0].name+"年龄更大");
        } else if (ageComparator.compare(studnets[0],studnets[1]) < 0) {
            System.out.println(studnets[1].name + "年龄更大");
        }else {
            System.out.println(studnets[0].name+" "+studnets[1].name+" 年龄相同");
        }

        /*    Arrays.sort(studnets,ageComparator);
        System.out.println("根据年龄比较： " + Arrays.toString(studnets));
        Arrays.sort(studnets,nameComparator);
        System.out.println("根据姓名比较： " + Arrays.toString(studnets));*/
    }


    public static void main1(String[] args) {
        int[] array = {4,53,2,45,2,5,7,1};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
}
